<!DOCTYPE html>
<html lang="zh-CN">

<head>
    <meta charset="UTF-8">
    <title>CI/CD</title>
    <link href="/static/bootstrap.min.css" rel="stylesheet">
    <script src="/static/bootstrap.bundle.js"></script>
</head>

<body class="bg-dark bg-opacity-75">
    <div class="container vh-100">
        <div class="row vh-100">
            <div class="col-4 m-auto p-5 justify-content-center bg-white rounded">
                <div class="mb-3">
                    <label class="form-label mb-1 text-black-50">用户名：</label>
                    <label>
                        <input type="text" class="form-control" id="username">
                    </label>
                </div>
                <div class="mb-4">
                    <label class="form-label mb-1 text-black-50">密码：</label>
                    <label>
                        <input type="password" class="form-control" id="password">
                    </label>
                </div>
                <div class="mb-1">
                    <button type="button" class="form-control btn-primary" onclick="login()">登录</button>
                </div>
            </div>
        </div>
    </div>
    <script>
        function login() {
            const username = document.querySelector("#username").value
            const password = document.querySelector("#password").value
            fetch("/login", {
                method: "POST",
                body: JSON.stringify({
                    username: username,
                    password: password
                })
            })
                .then(response => response.json())
                .then(data => {
                    if (data.code === 1) {
                        sessionStorage.setItem("token", data.result)
                        window.location.href = "/service/index"
                    } else {
                        alert(data.result)
                    }
                })
        }
    </script>
</body>

</html>